package com.ctec.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ctec.mapper.ClickhouseMapper;
import com.ctec.service.DataIntegrationService;
import com.ctec.util.R;
import com.ctec.vo.DynamicData;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class DataIntegrationServiceImpl implements DataIntegrationService {


    @Resource
    private ClickhouseMapper clickhouseMapper;

    @Override
    public R doIntegration(DynamicData filedChangeForm) {
        String tableName = filedChangeForm.getTableName();
        try {
            for (HashMap filedItem : filedChangeForm.getFiledItems()) {
                //数据直接存入Clickhouse
                clickhouseMapper.insertData(tableName, JSON.toJSONString(filedItem));
            }

        }catch (Exception e){
            return R.fail();

        }

        return R.ok();
    }
}
